import { cafReq } from "..";

// import { parseStrEmpty } from "@/utils/validate";
export const baseURL = `${import.meta.env.VITE_FIN_URL}/finance-user`;

// 查询用户列表
export const listUser = async (params: any) => {
  return await cafReq(0, { baseURL }).post(`/sys/user/search`, params);
};

// 查询用户详细
export const getUser = async (businessId: string) => {
  return await cafReq(0, { baseURL }).get(`/sys/user/v1/get/${businessId}`);
};

// 新增用户
export const addUser = async (data: any) => {
  return await cafReq(0, { baseURL }).post(`/sys/user/v1/add`, data);
};

// 修改用户
export const updateUser = async (data: any) => {
  return await cafReq(0, { baseURL }).post(`/sys/user/v1/update`, data);
  console.log(data);
};

// 删除用户
export const delUser = async (businessId: any) => {
  return await cafReq(0, { baseURL }).delete(
    `/sys/user/v1/delete/${businessId}`
  );
};

// 用户密码重置
export const resetUserPwd = async (businessId: string, password: any) => {
  return await cafReq(0, { baseURL }).post(`/sys/user/v1/changePassword`, {
    businessId,
    password,
  });
};

// 用户状态修改
export const changeUserStatus = async (businessId: string, flags: any) => {
  const data = {
    businessId,
    flags,
  };
  return await cafReq(0, { baseURL }).post(`/sys/user/v1/changeFlag`, data);
};

// 查询用户个人信息
export const getUserProfile = async () => {
  return await cafReq(0, { baseURL }).post(`/sys/user/getNowUser`);
};

// 修改用户个人信息
export const updateUserProfile = async (params: any) => {
  return await cafReq(0, { baseURL }).post(` /sys/user/v1/update`, {
    params,
  });
};

// 用户密码重置
export const updateUserPwd = async (newPassword: string) => {
  return await cafReq(0, { baseURL }).post(`/sys/user/v1/changePassword`, {
    params: { businessId: 0, password: newPassword },
  });
};

// 用户头像上传
export const uploadAvatar = async () => {
  //   return request({
  //     url: "/system/user/profile/avatar",
  //     method: "post",
  //     data: data,
  //   });
};

// 查询授权角色
export const getAuthRole = async (businessId: any) => {
  return await cafReq(0, { baseURL }).get(
    `/sys/role/v1/getUserAllRoles/${businessId}`
  );
};

// 保存授权角色
export const updateAuthRole = async (roleObj: any) => {
  console.log(roleObj);
};

// 查询部门下拉树结构
export const deptTreeSelect = async () => {
  //   return request({
  //     url: "/system/user/deptTree",
  //     method: "get",
  //   });
};
